﻿using mars_server.csharp.AO;
using mars_server.csharp.AO.impl;
using mars_server.csharp.CO;
using mars_server.csharp.enums;
using mars_server.csharp.socket;
using mars_server.csharp.Util;
using mars_server.csharp.VO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace mars_server.csharp.controller
{
    public class DispatcherController
    {
        private DispatcherController() { }
        private static readonly DispatcherController instance = new DispatcherController();

        VerifyController verifyController = VerifyController.Instance;

        FriendController friendController = FriendController.Instance;

        ChatController chatController = ChatController.Instance;

        HeartController heartController = HeartController.Instance;

        GroupController groupController = GroupController.Instance;
        public static DispatcherController Instance
        {
            get
            {
                return instance;
            }
        }

        public void dispacther(MessageCO messageCO,UserSocket userSocket)
        {
            int requestType = messageCO.type;
            switch(requestType)
            {
                case (int)RequestEnum.request.Login:
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【*发起登录请求】--|");
                    verifyController.Login(messageCO,userSocket);
                    break;

                case (int)RequestEnum.request.FindUser:
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【*搜寻用户】--|");
                    friendController.findOnlineUser(messageCO,userSocket);
                    break;

                case (int)RequestEnum.request.GetFriends:
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【*获取好友】--|");
                    friendController.getFriends(messageCO, userSocket);
                    break;

                case (int)RequestEnum.request.User://获取用户信息
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【*获取用户信息】--|");
                    friendController.getFriendInfo(messageCO, userSocket);
                    break;

                case (int)RequestEnum.request.SingleChatContent:
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【*单人聊天信息转发】--|");
                    chatController.sendSingleChatMsg(messageCO, userSocket);
                     break;

                case (int)RequestEnum.request.GroupChatContent:
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【群聊天信息转发】--|");
                    chatController.sendGroupChatMsg(messageCO, userSocket);
                    break;

                case (int)RequestEnum.request.HeartBeats:
                    Console.WriteLine("[info]:|-【心跳】" + SocketUtil.getSocketInfo(userSocket) + "--|");
                    heartController.dealHeartRequest(messageCO, userSocket);
                    break;

                case (int)RequestEnum.request.GetFriendsForGroup:
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【*获取在线好友】--|");
                    friendController.getFriends(messageCO, userSocket);
                    break;

                case (int)RequestEnum.request.AddFriendNotify:
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【*添加好友请求】--|");
                    friendController.dealAddFriendRequest(messageCO, userSocket);
                    break;

                case (int)RequestEnum.request.DeleteFriend:
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【*删除好友请求】--|");
                    friendController.dealDeleteFriendRquest(messageCO, userSocket);
                    break;

                case (int)RequestEnum.request.CreateGroup:
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【*创建群操作】--|");
                    groupController.createGroup(messageCO,userSocket);
                    break;
                case (int)RequestEnum.request.GetGroupUsers:
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【*查询群信息】--|");
                    groupController.queryGroupInfo(messageCO, userSocket);
                    break;
                case (int)RequestEnum.request.GetGroupList:
                    Console.WriteLine("[info]:|-" + SocketUtil.getSocketInfo(userSocket) + "【*获取群列表】--|");
                    groupController.getGroupList(messageCO, userSocket);
                    break;
            }

        }

    }
}
